package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/09 21:57
 **/
public class Day24_3_Num28_StrStr {
    class Solution {
        public int strStr(String haystack, String needle) {
            if(needle == null) return 0;
            for(int i = 0;i < haystack.length();i++){
                int index = i, j = 0;
                if(needle.charAt(j) == haystack.charAt(index)){
                    while(j < needle.length() && index < haystack.length() &&
                            needle.charAt(j) == haystack.charAt(index)){
                        j++;index++;
                    }
                    if(j == needle.length()) return i;
                }
            }
            return -1;
        }
    }
}